// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function toggle_fade(element)
{
    if ( $(element).style.display == 'none')
        new Effect.SlideDown(element)
    else
        new Effect.SlideUp(element) 
}

// Taken from http://www.alexking.org/blog/2003/06/02/inserting-at-the-cursor-using-javascript/
function insertAtCursor(myField, myValue) {
//IE support
    if (document.selection) {
        myField.focus();
        sel = document.selection.createRange();
        sel.text = myValue;
        }
//MOZILLA/NETSCAPE support
    else if (myField.selectionStart || myField.selectionStart == '0') {
        var startPos = myField.selectionStart;
        var endPos = myField.selectionEnd;
        myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
    } else {
        myField.value += myValue;
    }
}

//Layout editor helper, it recives a string
// whit to integers the first is the article id and the second is the session id, try to change this
// using CDATA instead of the id of the paragraph
function addToLayout(element, layout)
{
    if(!layout)
      var layout = new Array();
    var tmp = new Array();
    var tmpObj = new Object();
    tmp = element.id.split(' '); 
    tmpObj.article = tmp[0]; 
    tmpObj.section = tmp[1];  
    layout.push(tmpObj);
    return layout;
 
}
//Updates the layout view ( just an element ) with a new one
function update_layout(layout, element)
{
    for (var i = 0; i<titles.length; i++)
    {
      new Insertion.Bottom(element, '<li>'+titles[i].toString()+'</li>')
    }
}

 function showLayoutResponse  (req)
{

  a = req.responseText.parseJSON();
   if (a.error == null)
      alert('Front page has been saved successfully');
   else
     alert(a.error);
  
}


